package com.wangjiyuan.giftshuo.ui.activity.listtop;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.Toast;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.base.BaseActivity;
import com.wangjiyuan.giftshuo.bean.listtopbean.commentbean.CommentBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.everydaybean.EveryDayBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.maybelikebean.MayBeLikeBean;
import com.wangjiyuan.giftshuo.bean.listtopbean.singleproductbean.SingleProductBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.other.ListTopContract;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.other.ListTopPresenter;

public class TaoBaoBuyActivity extends BaseActivity implements ListTopContract.IListTopView{

    private Toolbar toolBar_taoBaoBuy;
    private WebView wv_taoBaoBuy;
    private ImageView img_share_taoBaoBuy;
    private SingleProductBean.DataBean dataBean;
    private int id;

    private ListTopContract.IListTopPresenter iListTopPresenter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tao_bao_buy);

        Intent intent = getIntent();
        id = (int) intent.getSerializableExtra("itemId");
        startMVP();
        initView();
    }

    private void startMVP() {
        iListTopPresenter = new ListTopPresenter(this);
        iListTopPresenter.getSingleProductData(id);
    }

    private void initData() {
        toolBar_taoBaoBuy.setTitle(dataBean.getName());
        setSupportActionBar(toolBar_taoBaoBuy);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        toolBar_taoBaoBuy.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        wv_taoBaoBuy.getSettings().setJavaScriptEnabled(true);
        wv_taoBaoBuy.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                wv_taoBaoBuy.loadUrl(url);
                return true;
            }
        });
        wv_taoBaoBuy.loadUrl(dataBean.getPurchaseUrl());

        img_share_taoBaoBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TaoBaoBuyActivity.this, "分享", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        toolBar_taoBaoBuy = (Toolbar) findViewById(R.id.toolBar_taoBaoBuy);
        wv_taoBaoBuy = (WebView) findViewById(R.id.wv_taoBaoBuy);
        img_share_taoBaoBuy = (ImageView) findViewById(R.id.img_share_taoBaoBuy);


    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void showErrorInfo(String msg) {

    }

    @Override
    public void getEveryDayData(EveryDayBean everyDayBean) {

    }

    @Override
    public void getMayBeLikeData(MayBeLikeBean mayBeLikeBean) {

    }

    @Override
    public void getCommentData(CommentBean commentBean) {

    }

    @Override
    public void getSingleProductData(SingleProductBean singleProductBean) {
        dataBean = singleProductBean.getData();
        initData();
    }
}
